import 'package:baselib/net/dioutils.dart';
import 'package:dio/dio.dart';

/**
 * request请求封装
 */
class RequestManager {
  //初始化dio
  static initDio({String baseUrl:''}){
    DioUtils.instance.initDio(baseUrl: baseUrl);
  }
  //切换设置公共headers
   static List<Map<String,dynamic>> _setCommHeaders(){
    // DioUtils.instance.setHeaders(headers: headers);
    return [{'name':'li'}];
  }
  //设置
  /**
   * post请求
   */
  static postData(String url,
      {
        String baseUrl, dynamic params, CancelToken cancelToken, Options options,
      }) {

    return DioUtils.instance.setBaseUrl(baseUrl: baseUrl).setHeaders(headers: _setCommHeaders()).
    requestNetwork("POST", url, params: params, queryParameters:{},options: options, cancelToken: cancelToken,);
  }
  /**
   * get请求
   */
  static getData(String url,
      {
        String baseUrl, Map<String,dynamic> params, Map<String, dynamic> queryParameters, CancelToken cancelToken, Options options}) {
    return DioUtils.instance.setBaseUrl(baseUrl: baseUrl).setHeaders(headers: _setCommHeaders()).
    requestNetwork("GET", url, params: params,queryParameters: queryParameters, options: options, cancelToken: cancelToken);
  }

  /**
   * put请求
   */
  static putData(String url,
      {
        String baseUrl, Map<String,dynamic> params, CancelToken cancelToken, Options options,
      }) {

    return DioUtils.instance.setBaseUrl(baseUrl: baseUrl).setHeaders(headers: _setCommHeaders()).
    requestNetwork("PUT", url,params: params,queryParameters :{}, options: options, cancelToken: cancelToken);
  }

  /**
   * delete请求
   */
  static deleteData(String url,
      {
        String baseUrl, Map<String,dynamic> params, CancelToken cancelToken, Options options,
      }) {

    return DioUtils.instance.setBaseUrl(baseUrl: baseUrl).setHeaders(headers: _setCommHeaders()).
      requestNetwork("DELETE", url, params: params,queryParameters :{}, options: options, cancelToken: cancelToken);
  }
}
